﻿using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Runtime.InteropServices;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace PepsiCo.RBS.CustomFields
{
    public class ColorPickerFieldControl : TextField
    {
        protected Label ColorPickerValueForDisplay;

        protected override string DefaultTemplateName
        {
            get
            {
                if (this.ControlMode == SPControlMode.Display)
                {
                    return this.DisplayTemplateName;
                }
                else
                {
                    return "ColorPickerFieldControl";
                }
            }
        }
        public override string DisplayTemplateName
        {
            get
            {
                return "ColorPickerFieldControlForDisplay";
            }
            set
            {
                base.DisplayTemplateName = value;
            }
        }
        protected override void CreateChildControls()
        {
            if (this.Field != null)
            {
                base.CreateChildControls();

                this.textBox = (TextBox)TemplateContainer.FindControl("TextField");
                this.ColorPickerValueForDisplay = (Label)TemplateContainer.FindControl("ColorPickerValueForDisplay");
            }
            if (this.ControlMode != SPControlMode.Display)
            {
                if (!this.Page.IsPostBack)
                {
                    if (this.ControlMode == SPControlMode.New)
                    {
                        textBox.Text = "";
                    }
                }
            }
            else
            {
                ColorPickerValueForDisplay.Text = (string)this.ItemFieldValue;
            }
        }
        public override object Value
        {
            get
            {
                EnsureChildControls();
                return base.Value;
            }
            set
            {
                EnsureChildControls();
                base.Value = (string)value;
            }
        }
    }
}
